<?php
/* tblVatRate */
class tblVatRate extends NocForm
	{
		protected $_ID                 = array();
		protected $_VatRate                 = array();

		function __construct()
		{
			parent::__construct();
			$this->getRow();
		}
		public function get_ID()
		{
				return  $this->_get_IDValue();
		}

		private function _get_IDValue()
		{
			if(isset($this->_ID['value']))
				return $this->_ID['value'];
			else
				return false;
		}

		public function get_VatRate()
		{
				return  $this->_get_VatRateValue();
		}

		private function _get_VatRateValue()
		{
			if(isset($this->_VatRate['value']))
				return $this->_VatRate['value'];
			else
				return false;
		}


		public function set_IDValue($strID)
		{
			if($this->validateInput("validatexxxxx", $strID, "ID "))
					return($this->_setNewValue($this->_ID, $strID));
			else
					return false;
		}

		public function set_VatRateValue($strVatRate)
		{
			if($this->validateInput("validatexxxxx", $strVatRate, "VatRate "))
					return($this->_setNewValue($this->_VatRate, $strVatRate));
			else
					return false;
		}
		public function update()
		{
			if($this->_boFailedValidation)
					return false;
					$strErrorMsg = "";
					$strSuccessMsg = "";
			if($this->get_ID() == "")
					return $this->_setFailScreens("Update aborted no record selected.", true);

			$strJoin = "";
			$strSql = "UPDATE tblVatRate
					SET ";
					if($this->_ID['updated'])
					{
						$strSql .= $strJoin." ID = '".$this->_ID['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_ID['oldvalue']."' to '".$this->_ID['value']."'<br/>";
						$strErrorMsg .= "ID not updated<br/>";					}

					if($this->_VatRate['updated'])
					{
						$strSql .= $strJoin." VatRate = '".$this->_VatRate['value']."' ";
						$strJoin = ",";
						$strSuccessMsg .= "Portal Address changed from '".$this->_VatRate['oldvalue']."' to '".$this->_VatRate['value']."'<br/>";
						$strErrorMsg .= "VatRate not updated<br/>";					}

			$strSql .= "WHERE ID = ". $this->get_ID();
			//Only execute sql if there is something to update.
			if($strJoin == ",")
			{
				//echo nl2br($strSql);
				if(!($DatabaseResult = mysql_query($strSql)))
					return $this->_setFailScreens($strErrorMsg);
				$GLOBALS['arrSuccessMessages'][] = $strSuccessMsg;
			}else
				$GLOBALS['arrSuccessMessages'][] = "No data hasn't changed so no updates made.";
			return(TRUE);
		}
			public function delete_tblVatRate()
			{
				if($this->get_IDValue() == "")
					return $this->_setFailScreens("Delete aborted no record selected.", true);
				
		
				/* Deleted port forward from agg */
				$strSql =   "DELETE FROM tblVatRate
		   					  WHERE ID		= ".$this->get_IDValue();
		
				$qryDeletetblVatRate = new MySqlResults($strSql);
		
				if(!$qryDeletetblVatRate->result)
					return ($this->_setFailScreens("An error occurred while trying to delete database entry."));
		
		
				$GLOBALS['arrSuccessMessages'][] = " has been removed";
				return true;
			}
		public function insert_tblVatRate()
		{
			/* Check that all required fields have been set */
			if (!($this->_validateAllFieldsSet()))
			{
				return ($this->_setFailScreens("Fields required to add a new record haven't all been set", true));
			}
			
			$strSql =   "INSERT INTO tblVatRate
						  (
		 	VatRate
)VALUE(
		 	$this->get_VatRateValue() 
			)";
			
			$qryInserttblVatRate = new MySqlResults($strSql);
		if ($qryInserttblVatRate->result)
		{
			/*Extra post sql processing  */
		}else
			return $this->_setFailScreens("Unable to add to  tblVatRate");
			
		return true;
	}
	}

?>